//
//  PayobjModel.swift
//
//  Created by eme on 2016/12/25
//  Copyright (c) . All rights reserved.
//

import Foundation
import SwiftyJSON
import ModelProtocol

class PayobjModel: ModelProtocol {
    
    // MARK: Declaration for string constants to be used to decode and also serialize.
    internal let kPayobjNoncestrKey: String = "noncestr"
    internal let kPayobjAppidKey: String = "appid"
    internal let kPayobjTimestampKey: String = "timestamp"
    internal let kPayobjPartneridKey: String = "partnerid"
    internal let kPayobjSignKey: String = "sign"
    internal let kPayobjPrepayidKey: String = "prepayid"
    internal let kPayobjTotalFeeKey: String = "total_fee"
    internal let kPayobjPackageKey: String = "package"
    
    
    // MARK: 属性
    var noncestr: String
    var appid: String
    var timestamp: UInt32
    var partnerid: String
    var sign: String
    var prepayid: String
    var totalFee: String
    var package: String
    
    
    // MARK: 实现ModelProtocol 协议， 解析json数据
    required  init?(json: JSON) {
        noncestr = json[kPayobjNoncestrKey].stringValue
        appid = json[kPayobjAppidKey].stringValue
        timestamp = json[kPayobjTimestampKey].uInt32Value
        partnerid = json[kPayobjPartneridKey].stringValue
        sign = json[kPayobjSignKey].stringValue
        prepayid = json[kPayobjPrepayidKey].stringValue
        totalFee = json[kPayobjTotalFeeKey].stringValue
        package = json[kPayobjPackageKey].stringValue
        
    }
    
    
    /**
     Generates description of the object in the form of a NSDictionary.
     - returns: A Key value pair containing all valid values in the object.
     */
    internal func dictionaryRepresentation() -> [String : AnyObject ] {
        
        var dictionary: [String : AnyObject ] = [ : ]
        
        dictionary.updateValue(noncestr as AnyObject, forKey: kPayobjNoncestrKey)
        
        dictionary.updateValue(appid as AnyObject, forKey: kPayobjAppidKey)
        
        dictionary.updateValue(partnerid as AnyObject, forKey: kPayobjPartneridKey)
        
        dictionary.updateValue(sign as AnyObject, forKey: kPayobjSignKey)
        
        dictionary.updateValue(prepayid as AnyObject, forKey: kPayobjPrepayidKey)
        
        dictionary.updateValue(totalFee as AnyObject, forKey: kPayobjTotalFeeKey)
        
        dictionary.updateValue(package as AnyObject, forKey: kPayobjPackageKey)
        
        
        return dictionary
    }
    
    
}
